package cn.com.backstage.controller;

import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Date;
import java.text.SimpleDateFormat;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import cn.com.api.entity.ApiU_against;

import cn.com.api.service.ApiU_againstService;
import cn.com.backstage.controller.base.U_againstBaseController;

import cn.com.util.*;

@Controller
@RequestMapping(Utils.SYS_BACKSTAGE + "/")
public class U_againstController extends U_againstBaseController {

	private static Logger logger = Logger.getLogger(U_againstController.class);

	@Autowired
	private ApiU_againstService apiU_againstService;

	/**
	 * 跳转到审核页面
	 * 
	 * @return
	 */
	@RequestMapping(value = "circleagainstdetail")
	public ModelAndView circleagainstdetail(HttpServletRequest request, HttpServletResponse response) throws Exception {
		ModelAndView mv = new ModelAndView("forward:/backstage/u_against_detail.jsp");
		String againstid = request.getParameter("againstid");
		ApiU_against u_against = apiU_againstService.findU_againstById(Integer.valueOf(againstid));
		mv.addObject("u_against", u_against);
		return mv;
	}

	/**
	 * 处理审核信息
	 * 
	 * @return
	 */
	@RequestMapping(value = "handeragainst")
	@ResponseBody
	public Object handeragainst(HttpServletRequest request, HttpServletResponse response, ApiU_against u_against)
			throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		try {
			ApiU_against against = apiU_againstService.findU_againstById(u_against.getId());
			against.setHandermsg(u_against.getHandermsg());
			against.setStatus(1);
			against.setUpdate_time(DateUtil.nowTimeToString());
			apiU_againstService.updateU_against(against);
			map.put(Utils.RESULT, Utils.RESULT_RC_SUCCESS);
			map.put(Utils.MESSAGE, "操作成功");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			map.put(Utils.RESULT, Utils.RESULT_RC_EXCEPTION);
			map.put(Utils.MESSAGE, "系统异常");
		}
		return map;
	}

}
